package com.summer.edu.controller;


import com.summer.R;
import com.summer.edu.entity.Course;
import com.summer.edu.entity.vo.CourseInfoVo;
import com.summer.edu.entity.vo.CoursePublishVo;
import com.summer.edu.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-01-13
 */
@RestController
@RequestMapping("/eduservice/course")
@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping
    public R getCourseList(){
        List<Course> list = courseService.list(null);
        return R.ok().data("list",list);
    }
    @PostMapping("addCourseInfo")
    public R addCourseInfo(@RequestBody CourseInfoVo courseInfoVo){
    String id=courseService.saveCourseInfo(courseInfoVo);
        return R.ok().data("courseId",id);
    }
    @GetMapping("getCourseInfo/{courseId}")
    public R getCourseInfo(@PathVariable String courseId){
      CourseInfoVo courseInfoVo=  courseService.getCourseInfo(courseId);
        return R.ok().data("courseInfoVo",courseInfoVo);
    }
    @PostMapping("updateCourseInfo")
    public R UpdateCourseInfo(@RequestBody CourseInfoVo vo){
       courseService.updateCourseInfo(vo);
        return R.ok();
    }
    @GetMapping("getPublishCourseInfo/{id}")
    public R getPublishCourseInfo(@PathVariable String id){
       CoursePublishVo coursePublishVo = courseService.publishCourseInfo(id);
       return R.ok().data("publishCourse",coursePublishVo);
    }
    @PostMapping("publishCourse/{id}")
    public R publishCourse (@PathVariable String id){
        Course course = new Course();
        course.setId(id);
        course.setStatus("Normal");
        courseService.updateById(course);
        return R.ok();
    }
    @DeleteMapping("{courseId}")
    public  R deleteCourse(@PathVariable String courseId){
        courseService.removeCourse(courseId);
        return  R.ok();
    }

}

